package com.itheima.controller;

import com.itheima.entity.PageResult;
import com.itheima.entity.QueryPageBean;
import com.itheima.entity.Result;
import com.itheima.pojo.Brand;
import com.itheima.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/brand")
public class BrandController {

    @Autowired
    private BrandService brandService;

    @GetMapping("/findPage")
    public PageResult findPage(QueryPageBean queryPageBean){
       PageResult pageResult = brandService.findPage(queryPageBean);
       return pageResult;
    }

    @GetMapping("/findAll")
    public Result findAll(){
        List<Brand> brandList = brandService.findAll();
        return  new Result(true,"查询成功", brandList);
    }


    @GetMapping("/findById")
    public Result<Brand> findById(Integer id){
        Brand brand = brandService.findById(id);
        return  new Result(true,"查询成功", brand);
    }
    @DeleteMapping("/delete/{id}")
    public Result handleDelete(@PathVariable Integer id){
        Boolean flag=brandService.deleteById(id);
        return new Result(flag,"删除成功","");
    }
    @PostMapping("/handleAdd")
    public Result handleAdd(@RequestBody Brand brand){
        Boolean flag = brandService.insertBrand(brand);
        return new Result(flag,"添加成功",null);
    }
    @PutMapping("/handleEdit")
    public Result handleEdit(@RequestBody Brand brand){
        Boolean flag = brandService.updateBrand(brand);
        return new Result(flag,"修改成功","null");
    }

}
